/*
 * $Id: Location.java 52 2010-01-11 01:42:30Z aaron.day $
 */
package org.crazydays.gameplan.map.location;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.crazydays.gameplan.map.Coordinate;

/**
 * Location is a data representation of a location on a game map.
 */
public class Location
    implements Comparable<Location>, Serializable
{
    /** serial version uid */
    public final static long serialVersionUID =
        "$Id: Location.java 52 2010-01-11 01:42:30Z aaron.day $".hashCode();

    /** name */
    protected String name;

    /** type */
    protected LocationType type;

    /** coordinates */
    protected List<Coordinate> coordinates = new ArrayList<Coordinate>();

    /**
     * Location constructor.
     */
    public Location()
    {
    }

    /**
     * Location constructor.
     * 
     * @param name Name
     */
    public Location(String name)
    {
        setName(name);
    }

    /**
     * Location constructor.
     * 
     * @param name Name
     * @param type Type
     * @param coordinates Coordinates
     */
    public Location(String name, LocationType type, List<Coordinate> coordinates)
    {
        setName(name);
        setType(type);
        setCoordinates(coordinates);
    }

    /**
     * Location constructor.
     * 
     * @param name Name
     * @param type Type
     */
    public Location(String name, LocationType type)
    {
        setName(name);
        setType(type);
    }

    /**
     * Set name.
     * 
     * @param name Name
     */
    public void setName(String name)
    {
        this.name = name;
    }

    /**
     * Get name.
     * 
     * @return Name
     */
    public String getName()
    {
        return name;
    }

    /**
     * Set location type.
     * 
     * @param type Type
     */
    public void setType(LocationType type)
    {
        this.type = type;
    }

    /**
     * Get type.
     * 
     * @return Type
     */
    public LocationType getType()
    {
        return type;
    }

    /**
     * Set coordinates.
     * 
     * @param coordinates Coordinates
     */
    public void setCoordinates(List<Coordinate> coordinates)
    {
        this.coordinates = coordinates;
    }

    /**
     * Get coordinates.
     * 
     * @return Coordinates
     */
    public List<Coordinate> getCoordinates()
    {
        return coordinates;
    }

    /**
     * Compare to game map.
     * 
     * @param location Location
     * @return Comparison
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    public int compareTo(Location location)
    {
        return getName().compareTo(location.getName());
    }

    /**
     * Equals.
     * 
     * @param object Object
     * @return Equals
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object object)
    {
        if (object == null) {
            return false;
        }

        if (!(object instanceof Location)) {
            return false;
        }

        Location l = (Location) object;

        if (getName() != null && !getName().equals(l.getName())) {
            return false;
        }

        if (getName() == null && l.getName() != null) {
            return false;
        }

        if (getType() != l.getType()) {
            return false;
        }

        if (getCoordinates().equals(l.getCoordinates())) {
            return false;
        }

        return true;
    }

    /**
     * HashCode.
     * 
     * @return HashCode
     * @see java.lang.Object#hashCode()
     */
    public int hashCode()
    {
        return getName().hashCode();
    }
}
